import {AfterViewInit, Component, EventEmitter, OnInit, Output} from '@angular/core';
import {company} from "app/share/produce-share.service";
import {HttpService} from "../share/http.service";
import {url} from "../share/url";
import set = Reflect.set;

@Component({
  moduleId: module.id,
  selector: 'my-system_keyword',
  templateUrl: 'system_keyword.component.html'
})

export class system_keywordComponent implements OnInit, AfterViewInit {
  public companyDetailUrl: string = url.url+'/app2/web/manage/webInfo/detail';
  public companyDetailPageUrl : string = url.url+'/app2/web/manage/page';
  public companyDetailParams: any = {};
  public companyDetailPageParams:any = {page:'company'};
  public companyDetailImage:any = [];
  public companyDetailModalShow:boolean = false;

  // @Output()
  // richTextFromCompany:EventEmitter<any> = new EventEmitter();
  // public companyPage:any={
  //   unitName:'',
  //   address:'',
  //   icp:'',
  //   openTime:'',
  //   fax:'',
  //   phone:''
  // };
  public inputValue : any ={
    unitName:'',
    address:'',
    icp:'',
    openTime:'',
    fax:'',
    phone:'',
    id:1
  };
  public company: Array<company>;//公司的相关介绍,从模拟数据中引入的,然后动态添加到页面上
  public showBoolean: boolean = false;//用来控制模态框的显示与否
  public richText: string = '';//表示该富文本的内容
  public companyUnique: string = 'companyDetail';
  // 用来控制显示几个文本框，传入modal模块中
  public needTwo: string = 'needTwo';
  //用来控制公司介绍的富文本内容和图片内容;
  public companyDetailToModal:any;
  public parentShowModel:boolean=false;
  constructor(
              private http: HttpService

  ) {
  }

  ngOnInit() {
    this.http.httpGet(this.companyDetailPageUrl,this.companyDetailPageParams)
      .subscribe((res)=>{
        console.log(res);
        let htmls = res.results.pagehtmls[0].htmls;
        this.companyDetailToModal = res.results.pagehtmls[0];
        // let richTextArray: any = [{
        //   id:htmls.id,
        //   html: htmls[0].html,
        //   position: htmls[0].position
        // }, {html: htmls[1].html, position: htmls[1].position}];
        // console.log(richTextArray);
        this.companyDetailImage = res.results.pagehtmls[0].images;
        console.log(this.companyDetailImage);
        this.richText = JSON.stringify(htmls);
        this.companyDetailModalShow = true;
        // $("#companyIcon").hide();
        // $(".publicArticle").css({padding:0})
        // this.richTextFromCompany.emit(this.richText)
        // console.log(this.richText);
        // this.companyPage=res;
      });
    this.http.httpGet(this.companyDetailUrl, this.companyDetailParams)
      .subscribe((res) => {
        // console.log(res);
        let page = res.results.webInfo;
        // console.log(page);
        this.inputValue = {
          unitName:page.unitName,
          address:page.address,
          icp:page.icp,
          openTime:page.openTime,
          fax:page.fax,
          phone:page.phone,
          id:page.id
        };
        this.parentShowModel = true;
        // console.log(this.inputValue)
        // this.company = res.results.webInfo
      });


    // this.company = this.getCompanyIntroduce.getCompany()
  }

  ngAfterViewInit() {
    // this.richText = this.company[0].richText

  }
  companyUnitName(e){
    this.inputValue.unitName = e.target.value;
  }
  companyAddress(e){
    this.inputValue.address = e.target.value;
  }

  companyIcp(e){
    this.inputValue.icp = e.target.value;
  }

  companyOpenTime(e){
    this.inputValue.openTime = e.target.value;
  }

  companyFax(e){
    this.inputValue.fax = e.target.value;
  }

  companyPhone(e){
    this.inputValue.phone = e.target.value;
  }

  comeFromModalBoolean(event: boolean) {
    this.ngOnInit();
    console.log("重新调用")
  }
  modifyCompany() {
    this.showBoolean = true;
  }
}
